package BasicKnowledge.Basic.IO;

import java.io.*;

/**
 * @time: 2021/2/2/002 21:23
 * @author: Zhurunhe
 */
public class Demo11 {
    public static void main(String[] args) throws IOException {
        //testPrintStream();
        testPrintWriter();



    }

    private static void testPrintWriter() throws IOException {
        PrintWriter printWriter=new PrintWriter(new FileWriter("G:/print.txt"));
        printWriter.print("这是字符打印流");
        try {
            FileInputStream fileInputStream=new FileInputStream("dsadadas");
        } catch (FileNotFoundException e) {
            e.printStackTrace(printWriter);
        }
        printWriter.close();


    }

    private static void testPrintStream() throws IOException {
        OutputStream outputStream=new FileOutputStream("G:/print.txt",true);
        PrintStream  printStream=new PrintStream(outputStream);
        printStream.print("Hello");
        printStream.println(" world");

        //System类的out成员就是PrintStream类型的打印流
        //System.out默认是在控制台输出的
        System.out.println("默认是在控制台输出的");
        System.setOut(printStream);//修改打印的显示的地方
        System.out.println("我不在控制台上打印了WO");


        //  在开发中也常将异常信息打印到日志文件中
        try {
            FileInputStream fileInputStream=new FileInputStream("dsadadas");
        } catch (FileNotFoundException e) {
            e.printStackTrace(printStream);
        }
        printStream.close();
    }


}
